
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:xin_he/configration/xin_he_env_config.dart';
import 'package:xin_he/utils/xh_styles.dart';


class XinHeToast {
  ///统一样式管理
  static double fontSize = 14;
  static Color backgroundColor = XinHeColor('#5C5C5C');
  static Color textColor = XinHeColor('#FFFFFF');

  ///顶部信息
  static top(String msg) {
    EasyLoading.dismiss();
    EasyLoading.instance
      ..displayDuration = const Duration(seconds: 2)
      ..indicatorType = EasyLoadingIndicatorType.circle
      ..loadingStyle = EasyLoadingStyle.custom
      ..backgroundColor = XinHeColor('#5C5C5C')
      ..indicatorColor = Colors.transparent
      ..maskType = EasyLoadingMaskType.none
      ..textColor = Colors.white
      ..maskColor = Colors.transparent
      ..radius = 4.0
      ..fontSize = 14
      ..contentPadding = const EdgeInsets.only(left: 12,right: 12,top: 8,bottom: 8);
    EasyLoading.showToast(msg,toastPosition: EasyLoadingToastPosition.top);
  }

  ///居中信息
  static center(String msg) {
    EasyLoading.dismiss();
    EasyLoading.instance
      ..displayDuration = const Duration(seconds: 2)
      ..indicatorType = EasyLoadingIndicatorType.circle
      ..loadingStyle = EasyLoadingStyle.custom
      ..backgroundColor = XinHeColor('#5C5C5C')
      ..indicatorColor = Colors.transparent
      ..maskType = EasyLoadingMaskType.none
      ..textColor = Colors.white
      ..maskColor = Colors.transparent
      ..radius = 4.0
      ..fontSize = 14
      ..contentPadding = const EdgeInsets.only(left: 12,right: 12,top: 8,bottom: 8)
      ..boxShadow = <BoxShadow>[];
    EasyLoading.showToast(msg,toastPosition: EasyLoadingToastPosition.center);
  }

  ///底部信息
  static bottom(String msg) {
    EasyLoading.dismiss();
    EasyLoading.instance
      ..displayDuration = const Duration(seconds: 2)
      ..indicatorType = EasyLoadingIndicatorType.circle
      ..loadingStyle = EasyLoadingStyle.custom
      ..backgroundColor = XinHeColor('#5C5C5C')
      ..indicatorColor = Colors.transparent
      ..maskType = EasyLoadingMaskType.none
      ..textColor = Colors.white
      ..maskColor = Colors.transparent
      ..radius = 4.0
      ..fontSize = 14
      ..contentPadding = const EdgeInsets.only(left: 12,right: 12,top: 8,bottom: 8)
      ..boxShadow = <BoxShadow>[];
    EasyLoading.showToast(msg,toastPosition: EasyLoadingToastPosition.bottom);
  }

  /// 调试信息
  /// 只有在非生产环境下打印
  static d(String msg) {
    if (const String.fromEnvironment(XinHeEnvName.envKey) != "online") return;
    center(msg);
  }

  ///加载框
  static loading([String? status]) {
    EasyLoading.show(status: status, maskType: EasyLoadingMaskType.black, dismissOnTap: false);
  }

  ///app定制加载框
  static xinHeloading([String? status]) {
    EasyLoading.instance
      ..displayDuration = const Duration(milliseconds: 2000)
      ..indicatorType = EasyLoadingIndicatorType.circle
      ..loadingStyle = EasyLoadingStyle.custom
      ..backgroundColor = Colors.transparent
      ..indicatorColor = Colors.transparent
      ..maskType = EasyLoadingMaskType.custom
      ..textColor = Colors.transparent
      ..maskColor = Colors.transparent
      ..boxShadow = <BoxShadow>[];
      // ..indicatorWidget = const KdLoadingWidget();
    EasyLoading.show();
  }

  ///app定制加载框
  static xinHeEasyShowText(String status) {
    EasyLoading.instance
      ..displayDuration = const Duration(seconds: 2)
      ..indicatorType = EasyLoadingIndicatorType.circle
      ..loadingStyle = EasyLoadingStyle.custom
      ..backgroundColor = XinHeColor('#5C5C5C')
      ..indicatorColor = Colors.transparent
      ..maskType = EasyLoadingMaskType.none
      ..textColor = Colors.white
      ..maskColor = Colors.transparent
      ..radius = 4.0
      ..fontSize = 14
      ..contentPadding = const EdgeInsets.only(left: 16,right: 16,top: 8,bottom: 8)
      ..boxShadow = <BoxShadow>[];
    EasyLoading.showToast(status,toastPosition: EasyLoadingToastPosition.center);
  }

  ///成功
  static success({required String status}) {
    EasyLoading.showSuccess(status);
  }

  ///失败
  static error({required String status}) {
    EasyLoading.showError(status);
  }

  ///取消加载框
  static cancel() {
    EasyLoading.dismiss();
  }
}